package com.java.zhuiyun.api.image_file.controller;

import com.java.zhuiyun.api.image_file.service.ImageFileService;
import com.java.zhuiyun.common.errorCode.CommonException;
import com.java.zhuiyun.common.response.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName ImageFileController
 * @Description TODO
 * @Author MJL
 * @Date 2023/9/13 22:50
 **/
@RestController
@RequestMapping("/ImageFile")
public class ImageFileController {
    @Resource
    ImageFileService imageFileService;
    /**
    * @Author MJL
    * @Description todo 上传图片
    * @Date 2023/9/13 23:14
    * @Return  * @param null
    */
    @PostMapping("/addImageFile")
    public CommonResult addImageFile(MultipartFile file) {
        return CommonResult.ok(imageFileService.addImageFile(file));
    }

    /**
    * @Author xy
    * @Description todo 图片上传返回id
    * @Date 2023/9/27 8:23
    * @Return  * @param null
    */
    @PostMapping("/addImageFile1")
    public String addImageFile1(MultipartFile file) {
        String s = imageFileService.addImageFile(file);
        return s;
    }

    /**
    * @Author MJL
    * @Description todo 查看图片
    * @Date 2023/9/14 23:51
    * @Return  * @param null
    */
    @GetMapping("/getImageById")
    public void getImageById(Integer id, HttpServletResponse response) throws CommonException {
        imageFileService.getImageById(id,response);
    }

    @GetMapping("/selectAll")
    public CommonResult selectAll(){
        return CommonResult.ok(imageFileService.selectAll());
    }
}
